
package com.cmc.dao.hibernate;

import java.util.List;

import com.cmc.dao.hibernate.BaseDaoHibernate;
import com.cmc.model.SystemCharacter;
import com.cmc.dao.SystemCharacterDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class SystemCharacterDaoHibernate extends BaseDaoHibernate implements SystemCharacterDao {

    /**
     * @see com.cmc.dao.SystemCharacterDao#getSystemCharacters(com.cmc.model.SystemCharacter)
     */
    public List getSystemCharacters(final SystemCharacter systemCharacter) {
        return getHibernateTemplate().find("from SystemCharacter");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.
        if (systemCharacter == null) {
            return getHibernateTemplate().find("from SystemCharacter");
        } else {
            // filter on properties set in the systemCharacter
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(systemCharacter).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(SystemCharacter.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }*/
    }

    /**
     * @see com.cmc.dao.SystemCharacterDao#getSystemCharacter(Long id)
     */
    public SystemCharacter getSystemCharacter(final Long id) {
        SystemCharacter systemCharacter = (SystemCharacter) getHibernateTemplate().get(SystemCharacter.class, id);
        if (systemCharacter == null) {
            log.warn("uh oh, systemCharacter with id '" + id + "' not found...");
            throw new ObjectRetrievalFailureException(SystemCharacter.class, id);
        }

        return systemCharacter;
    }

    /**
     * @see com.cmc.dao.SystemCharacterDao#saveSystemCharacter(SystemCharacter systemCharacter)
     */    
    public void saveSystemCharacter(final SystemCharacter systemCharacter) {
        getHibernateTemplate().saveOrUpdate(systemCharacter);
    }

    /**
     * @see com.cmc.dao.SystemCharacterDao#removeSystemCharacter(Long id)
     */
    public void removeSystemCharacter(final Long id) {
        getHibernateTemplate().delete(getSystemCharacter(id));
    }
}
